package uscdb.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;

import uscdb.service.LogicServiceI;
import uscdb.service.ReviewServiceI;

/**
 * 图表控制器
 */
@Controller
@RequestMapping("/chartController")
public class ChartController extends BaseController {

	@Autowired
	private LogicServiceI logicService;

	@Autowired
	private ReviewServiceI reviewService;

	/**
	 * 功能：获取logic对应的点记率，返回给页面制作图表
	 * 
	 * @return
	 */
	@RequestMapping("/logicHeatChart")
	public String logicHeatChart(HttpServletRequest request) {
		String number = (String) request.getAttribute("number");
		String logicHeatChartData = JSON.toJSONString(logicService.logicHeatChart(number));
		request.setAttribute("logicHeatChart", logicHeatChartData);
		return "/charts/logicHeatChart";
	}

	/**
	 * 功能：将前 number 个review的数据通过图表展示出来
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/reviewChart")
	public String reviewChart(HttpServletRequest request) {
		String number = (String) request.getAttribute("number");
		String reviewChartData = JSON.toJSONString(reviewService.reviewChart(number));
		request.setAttribute("reviewChart", reviewChartData);
		return "/charts/reviewChart";
	}

	/**
	 * 功能：将前 number 个员工的review数据通过图表展示出来
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/peopleReviewChart")
	public String peopleReviewChart(HttpServletRequest request) {
		String number = (String) request.getAttribute("number");
		String peopleReviewChartData = JSON.toJSONString(reviewService.peopleReviewChart(number));
		request.setAttribute("peopleReviewChart", peopleReviewChartData);
		return "/charts/peopleReviewChart";
	}

}
